package com.ruoyi.project.abucoder.point.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.abucoder.point.domain.UserPoint;
import com.ruoyi.project.abucoder.point.service.IUserPointService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 用户次数Controller
 * 
 * @author wuyy
 * @date 2024-04-28
 */
@Controller
@RequestMapping("/abucoder/point")
public class UserPointController extends BaseController
{
    private String prefix = "abucoder/point";

    @Autowired
    private IUserPointService userPointService;

    @RequiresPermissions("abucoder:point:view")
    @GetMapping()
    public String point()
    {
        return prefix + "/point";
    }

    /**
     * 查询用户次数列表
     */
    @RequiresPermissions("abucoder:point:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UserPoint userPoint)
    {
        startPage();
        List<UserPoint> list = userPointService.selectUserPointList(userPoint);
        return getDataTable(list);
    }

    /**
     * 导出用户次数列表
     */
    @RequiresPermissions("abucoder:point:export")
    @Log(title = "用户次数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UserPoint userPoint)
    {
        List<UserPoint> list = userPointService.selectUserPointList(userPoint);
        ExcelUtil<UserPoint> util = new ExcelUtil<UserPoint>(UserPoint.class);
        return util.exportExcel(list, "用户次数数据");
    }

    /**
     * 新增用户次数
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户次数
     */
    @RequiresPermissions("abucoder:point:add")
    @Log(title = "用户次数", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(UserPoint userPoint)
    {
        return toAjax(userPointService.insertUserPoint(userPoint));
    }

    /**
     * 修改用户次数
     */
    @RequiresPermissions("abucoder:point:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        UserPoint userPoint = userPointService.selectUserPointById(id);
        mmap.put("userPoint", userPoint);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户次数
     */
    @RequiresPermissions("abucoder:point:edit")
    @Log(title = "用户次数", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(UserPoint userPoint)
    {
        return toAjax(userPointService.updateUserPoint(userPoint));
    }

    /**
     * 删除用户次数
     */
    @RequiresPermissions("abucoder:point:remove")
    @Log(title = "用户次数", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(userPointService.deleteUserPointByIds(ids));
    }
}
